package com.rd.student.ruanjian.class4.zhangrui.day8_8Exam;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Locating {
    public static void main(String[] args) {
        Map<String,String> playerTeamMap=playerFile("player.txt");
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入球员姓名");
        String playerName=sc.nextLine();

        String teamName=playerTeamMap.get(playerName);
        if (teamName!=null){
            System.out.println("该球员属于"+teamName);
        }else {
            System.out.println("该球员不存在");
        }
    }

    static Map<String,String> playerFile(String file){
        Map<String,String> playerTeamMap =new HashMap<>();
        try {
            BufferedReader reader=new BufferedReader(new FileReader(file));
            String str;
            while ((str=reader.readLine())!=null){
                String[] arr=str.split("，");
                if (arr.length==2){
                    String playerName=arr[0];
                    String teamName=arr[1];
                    playerTeamMap.put(playerName,teamName);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
return playerTeamMap;
    }
}
